﻿using System;
using System.IO;
using System.Xml.Serialization;

namespace AiAsteriods.Game.Tools {
  public static class Serializer<T> {
    private static XmlSerializer xs = new XmlSerializer(typeof(T));

    public static void Serialize(string filename, Object obj) {
      using (FileStream fs = new FileStream(filename, FileMode.Create, FileAccess.Write)) {
        xs.Serialize(fs, obj);
      }
    }

    public static T Deserialize(string filename) {
      T data;
      using (FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read)) {
        data = (T)xs.Deserialize(fs);
      }
      return data;
    }
  }
}
